home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / others / pcal / pcaldefs.h < prev    next >
C/C++ Source or Header  |  1992-02-21  |  18KB  |  598 lines

  1. /*
  2.  * pcaldefs.h - definitions for Pcal program
  3.  *
  4.  * Revision history:
  5.  *
  6.  *    4.3    AWR    12/05/91    Revise moonfile name templates for
  7.  *                    consistency with current standards
  8.  *                    for substituting year in strings
  9.  *
  10.  *            12/03/91    Add support for -s flag
  11.  *
  12.  *            10/17/91    Add support for -Z flag and subflags;
  13.  *                    removed obsolete PUTSTR macro
  14.  *
  15.  *    4.2    AWR    10/08/91    Add support for -[kK] flags; renamed
  16.  *                    START_DAY as START_BOX for clarity
  17.  *
  18.  *            10/03/91    Add various definitions relating to
  19.  *                    "note/<n>"
  20.  *
  21.  *            09/30/91    Add MAX_IF_NESTING (related to "elif";
  22.  *                    cf. read_datefile() in readfile.c)
  23.  *
  24.  *    4.11    AWR    08/20/91    Add "nearest" keyword (as per Andy
  25.  *                    Fyfe)
  26.  *
  27.  *    4.1    AWR    08/16/91    Add support for -G flag
  28.  *
  29.  *    4.0    AWR    03/01/91    Add STDLIB macro for systems which
  30.  *                    support <stdlib.h>
  31.  *
  32.  *        AWR    02/22/91    add definitions for MS-DOS support (as
  33.  *                    per Floyd Miller)
  34.  *
  35.  *        AWR    02/19/91    revise ORD_XXX to support negative
  36.  *                    ordinals
  37.  *
  38.  *                    add definitions for Amiga support (as
  39.  *                    per Bill Hogsett)
  40.  *
  41.  *        AWR    02/06/91    additional defs for expression
  42.  *                    processing
  43.  *
  44.  *        AWR    02/04/91    support "year" as additional month
  45.  *                    name; use negative numbers for
  46.  *                    special ordinal codes (reserve
  47.  *                    positive numbers for ordinals)
  48.  *
  49.  *            01/28/91    miscellaneous new constants/macros
  50.  *
  51.  *            01/07/91    add FEB_29_OK (cf. enter_day_info())
  52.  *
  53.  *    3.0    AWR    12/10/90    support "weekday", "workday",
  54.  *                    "holiday", et. al.
  55.  *
  56.  *        AWR    11/13/90    extracted from pcal.c; added scale and
  57.  *                    translation support (-x, -y, -X, -Y);
  58.  *                    added -j, -J flags
  59.  *
  60.  */
  61.  
  62. /*
  63.  * System dependencies:
  64.  */
  65.  
  66. #ifdef VMS        /* VMS oddities isolated here */
  67.  
  68. #include <ssdef.h>    /* required for trnlog() */
  69. #include <descrip.h>
  70.  
  71. #define HOME_DIR    "SYS$LOGIN"
  72. #define DATEFILE    "calendar.dat"
  73. #define MOONFILE    "moon%y.dat"    /* '%y' replaced with year */
  74. #define DEFAULT_OUTFILE    "calendar.ps"
  75. #define START_PATH    '['
  76. #define END_PATH    ']'
  77.  
  78. #define EXIT_SUCCESS    1        /* VMS exit() parameters */
  79. #define EXIT_FAILURE    3
  80.  
  81. #else
  82. #ifdef AMIGA        /* more oddities for Amiga */
  83.  
  84. #include <string.h>
  85.  
  86. #define PROTOS                /* compiler accepts prototypes */
  87. #define STDLIB                /* system has <stdlib.h> */
  88. #define HOME_DIR    "RAM:"
  89. #define DATEFILE    "s:calendar.dat"
  90. #define MOONFILE    "s:.moon%y"    /* '%y' replaced with year */
  91. #define DEFAULT_OUTFILE    "RAM:calendar.ps"
  92. #define START_PATH    '/'
  93. #define END_PATH    '/'
  94.  
  95. #else
  96. #ifdef DOS        /* even more oddities for MS-DOS */
  97.  
  98. #define DATEFILE    "pcal.dat"
  99. #define MOONFILE    "moon%y.dat"    /* '%y' replaced with year */
  100. #define START_PATH    '\\'
  101. #define END_PATH    '\\'
  102. #define HOME_DIR    "HOME"
  103. #define ALT_DATEFILE    "calendar"    /* for backward compatibility */
  104.  
  105. #else            /* neither VMS, Amiga, nor MS-DOS - assume Un*x */
  106.  
  107. #define UNIXX        /* to distinguish Un*x from others */
  108.  
  109. #define HOME_DIR    "HOME"
  110. #define DATEFILE    ".calendar"
  111. #define ALT_DATEFILE    "calendar"    /* for backward compatibility */
  112. #define MOONFILE    ".moon%y"    /* '%y' replaced with year */
  113. #define ALT_MOONFILE    "moon%y"    /* analogous to ALT_DATEFILE */
  114. #define START_PATH    '/'
  115. #define END_PATH    '/'
  116.  
  117. #endif
  118. #endif
  119. #endif
  120.  
  121. /* define OUTFILE to DEFAULT_OUTFILE if defined, otherwise to "" (stdout) */
  122.  
  123. #ifdef DEFAULT_OUTFILE
  124. #define OUTFILE        DEFAULT_OUTFILE
  125. #else
  126. #define OUTFILE        ""
  127. #endif
  128.  
  129. /* PROTOS may be defined independently of __STDC__ for compilers which
  130.  * support function prototypes but are not fully ANSI-compliant
  131.  */
  132.  
  133. #if defined(__STDC__) && ! defined(PROTOS)
  134. #define PROTOS    
  135. #endif
  136.  
  137. /* STDLIB may be defined independently of __STDC__ for systems which
  138.  * support <stdlib.h> but are not fully ANSI-compliant
  139.  */
  140.  
  141. #if defined(__STDC__) && ! defined(STDLIB)
  142. #define STDLIB            /* cf. {no}protos.h */
  143. #endif
  144.  
  145. #ifdef STDLIB            /* include <stdlib.h> if known to exist */
  146. #include <stdlib.h>
  147. #endif
  148.  
  149. /* EXIT_SUCCESS and EXIT_FAILURE should be defined in <stdlib.h>
  150.  * (or above if non-standard); define here if necessary
  151.  */
  152.  
  153. #ifndef EXIT_SUCCESS
  154. #define EXIT_SUCCESS    0
  155. #endif
  156. #ifndef EXIT_FAILURE
  157. #define EXIT_FAILURE    1
  158. #endif
  159.  
  160. /* definition of NULL (if needed) */
  161.  
  162. #ifndef NULL
  163. #define NULL    0
  164. #endif
  165.  
  166. /*
  167.  * Environment variables (global symbol, logical name on VMS):
  168.  */
  169.  
  170. #define PCAL_OPTS    "PCAL_OPTS"    /* command-line flags */
  171. #define PCAL_DIR    "PCAL_DIR"    /* calendar file directory */
  172. #define PATH_ENV_VAR    "PATH"        /* cf. find_executable() (pcalutil.c) */
  173.  
  174. /*
  175.  * Function-like macros:
  176.  */
  177.  
  178. #define FPR        (void)fprintf
  179. #define PRT        (void)printf
  180.  
  181. #define PUTCHAR(_c) \
  182.     PRT((_c) == ' ' || isalnum(_c) ? "%c" : "\\%03o" , (_c) & 0377)
  183.  
  184. #define IS_LEAP(y)    ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
  185. #define LENGTH_OF(m, y) (month_len[(m)-1] + ((m) == FEB && IS_LEAP(y)))
  186. #define YEAR_LEN(y)    (IS_LEAP(y) ? 366 : 365)
  187. #define DAY_OF_YEAR(m, d, y) ((month_off[(m)-1] + ((m) > FEB && IS_LEAP(y))) + d)
  188. #define OFFSET_OF(m, y) ((month_off[(m)-1] + ((m) > FEB && IS_LEAP(y))) % 7)
  189. #define FIRST_OF(m, y)    calc_weekday(m, 1, y)
  190. #define START_BOX(m, y)    ((FIRST_OF(m, y) - first_day_of_week + 7) % 7)
  191.  
  192. #define PREV_MONTH(m, y) ((m) == JAN ? DEC : (m) - 1)
  193. #define PREV_YEAR(m, y)  ((m) == JAN ? (y) - 1 : (y))
  194. #define NEXT_MONTH(m, y) ((m) == DEC ? JAN : (m) + 1)
  195. #define NEXT_YEAR(m, y)  ((m) == DEC ? (y) + 1 : (y))
  196.  
  197. #define INIT_COLORS    memcpy(day_color, default_color, sizeof(day_color))
  198.  
  199. #define P_LASTCHAR(p)    ((p) && *(p) ? (p) + strlen(p) - 1 : NULL)
  200. #define LASTCHAR(p)    (p)[strlen(p) - 1]
  201.  
  202. #define IS_NUMERIC(p)    ((p)[strspn((p), DIGITS)] == '\0')
  203. #define IS_WILD(w)    ((w) >= WILD_FIRST && (w) <= WILD_LAST)
  204.  
  205. #define MAKE_DATE(dt, m, d, y) \
  206.     if (1) { (dt).mm = m; (dt).dd = d; (dt).yy = y; } else
  207.  
  208. #define ERR(errmsg) \
  209.     FPR(stderr, E_ILL_LINE, progname, errmsg, filename, line);
  210.  
  211. #define DEBUG(f)    ((debug_flags & f) != 0)
  212.  
  213. #ifdef __STDC__
  214. #define TOLOWER(c)    tolower(c)
  215. #else
  216. #define TOLOWER(c)    (isupper(c) ? tolower(c) : (c))
  217. #endif
  218.  
  219. #ifndef isodigit            /* rare */
  220. #define isodigit(c)    ((c) >= '0' && (c) <= '7')
  221. #endif
  222. #ifndef isxdigit            /* ANSI standard */
  223. #define isxdigit(c) \
  224.     (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
  225. #endif
  226.  
  227. /* debug subflag codes (must be distinct) - cf. pcallang.h */
  228.  
  229. #define DEBUG_DATES    (1 << 1)
  230. #define DEBUG_MOON    (1 << 2)
  231. #define DEBUG_PATHS    (1 << 3)
  232. #define DEBUG_OPTS    (1 << 4)
  233. #define DEBUG_PP    (1 << 5)
  234. #define DEBUG_TEXT    (1 << 6)
  235.  
  236. /* preprocessor token codes - cf. get_token(), pcallang.h */
  237.  
  238. #define PP_DEFINE     0
  239. #define PP_ELIF         1
  240. #define PP_ELSE         2
  241. #define PP_ENDIF     3
  242. #define PP_IFDEF     4
  243. #define PP_IFNDEF     5
  244. #define PP_INCLUDE     6
  245. #define PP_UNDEF     7
  246. #define PP_OTHER    -1    /* not pp token */
  247.  
  248. /* ordinal number codes - cf. get_ordinal(), pcallang.h */
  249.  
  250. #define ORD_NEGNUM    -1    /* negative ordinal (-2nd == next to last) */
  251. #define ORD_POSNUM     1    /* positive ordinal */
  252. #define ORD_ODD         2    /* special codes for "odd" and "even" */
  253. #define ORD_EVEN     3
  254. #define ORD_ALL         4    /* special code for "all" used as ordinal */
  255. #define ORD_OTHER     0    /* not ordinal token */
  256.  
  257. /* moon phase codes - cf. pcallang.h and moonphas.c; these must take the
  258.  * values 0 (NM) .. 3 (3Q) since they are used in phase calculations
  259.  */
  260.  
  261. #define MOON_NM         0    /* new moon */
  262. #define MOON_1Q         1    /* first quarter */
  263. #define MOON_FM          2    /* full moon */
  264. #define MOON_3Q         3    /* last quarter */
  265. #define MOON_OTHER    -1    /* unrecognizable */
  266.  
  267. /* date type codes - cf. date_type(), get_keywd(), and pcallang.h */
  268.  
  269. #define DT_ALL         0    /* "all" keyword" */
  270. #define DT_NOTE         1    /* "note" keyword */
  271. #define DT_OPT         2    /* "opt" keyword */
  272. #define DT_YEAR         3    /* "year" keyword */
  273. #define DT_MONTH     4    /* name of month */
  274. #define DT_DATE         5    /* date of form dd/mm{/yy} or mm/dd{/yy} */
  275. #define DT_EURDATE     6    /* European date of form dd <month> */
  276. #define DT_ORDINAL     7    /* ordinal (first, 1st, ... last) */
  277. #define DT_WEEKDAY     8    /* weekday name */
  278. #define DT_OTHER    -1    /* unrecognizable first token */
  279.  
  280. /* preposition token codes - cf. get_prep(), pcallang.h */
  281.  
  282. #define PR_BEFORE     0
  283. #define PR_ON_BEFORE     1
  284. #define PR_AFTER     2
  285. #define PR_ON_AFTER     3
  286. #define PR_NEAREST     4
  287. #define PR_OTHER    -1    /* not a preposition */
  288.  
  289.  
  290. /*
  291.  * Miscellaneous other constants:
  292.  */
  293.  
  294. #define FALSE        0    /* pseudo-Booleans */
  295. #define TRUE        1
  296.  
  297. #define MAX_FILE_NESTING 10    /* maximum nesting level for file inclusio